# #Lagos download script
LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
#mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
Iowa_Illinois <- states %>%
filter(name %in% c('Iowa', 'Illinois')) %>%
st_transform(2163)
mapview(Iowa_Illinois)
combined? How does this compare to Minnesota?
A: Iowa and Illinois have 16,466 sites, fewer than Minnesota, which has 29,038.
Iowa_Illinois_lakes <- spatial_lakes[Iowa_Illinois,]
nrow(Iowa_Illinois_lakes)
## [1] 16466
nrow(minnesota_lakes)
## [1] 29038
A: As can be seen in the histogram below, both Iowa and Minnesota show a larger distribution of numbers with smaller lakes. However, since the number of lakes in Minnesota is much higher than in Iowa, it can be seen that the distribution of lakes is more diverse and wider.
# Make Iowa's lake size data not Iowa_Illinois, using lake area
Iowa <- states %>%
filter(name=='Iowa') %>%
st_transform(2163)
Iowa_lakes <- spatial_lakes[Iowa,]
Iowa_lakes_size <- data.frame(Iowa_lakes$lake_area_ha) %>%
rename(Lake_Size=1) %>%
mutate(State='Iowa')
# Make Minnesota's lakes size data in similar way
minnesota_lakes_size <- data.frame(minnesota_lakes$lake_area_ha) %>%
rename(Lake_Size=1) %>%
mutate(State='Minnesota')
# Bind two data frames to make a plot
Compare_lake_size <- rbind(Iowa_lakes_size, minnesota_lakes_size)
# Make a histogram plot
ggplot(Compare_lake_size, aes(x=Lake_Size, fill=State)) +
xlim(1,200) +
xlab('Lake Size(ha)') +
geom_histogram(bins = 100, alpha=0.5, position = "identity") +
theme_few() +
scale_color_few() +
theme(legend.position=c(0.8,0.8))
Iowa_Illinois_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
A: For comparing lake size in another way, you can use perimeter length of lakes instead of lake area. The map below shows the variation of lake size using perimeter of lakes in three states.
Compare_lake_length <- rbind(minnesota_lakes, Iowa_Illinois_lakes)
Compare_lake_length %>%
arrange(-lake_perim_meters) %>%
slice(1:1000) %>%
mapview(., zcol='lake_perim_meters')